#pragma once

#include <iostream>
#include "Protocol.hpp"

//计算逻辑
class Calculator
{
public:
    Calculator()
    {
    }

    // 对相应的请求进行相应的应答
    Response Execute(const Request &req)
    {
        // 拿到结构化的数据
        Response resp;

        std::cout<<"对相应的请求进行计算"<<std::endl;
        switch (req.Oper())
        {
        case '+':
            resp.SetResult(req.X() + req.Y());
            break;
        case '-':
            resp.SetResult(req.X() - req.Y());
            break;
        case '*':
            resp.SetResult(req.X() * req.Y());
            break;
        case '/':
            if (req.Y() == 0)
            {
                resp.SetCode(1); // 1就是除0错误
            }
            else
            {
                resp.SetResult(req.X() / req.Y());
            }
            break;
        default:
            resp.SetCode(2); // 无法计算的类别
            break;
        }
        return resp;
    }
    ~Calculator()
    {

    }
};